//
//  PublicFunction.swift
//  YiDa
//
//  Created by zhoufei on 16/6/28.
//  Copyright © 2016年 ZhouFei. All rights reserved.
//

import Foundation

class PublicFunction: NSObject {
    static func getFourCode()->String{
        var str = "1111"
        let dateStamp:NSTimeInterval = NSDate().timeIntervalSince1970
        print(String(Double(dateStamp)))
        str = String(Double(dateStamp)).componentsSeparatedByString(".")[1]
        
        switch str.characters.count {
        case 0:
            str = "1811"
            break
        case 1:
            str = str + "000"
            break
        case 2:
            str = "00" + str
            break
        case 3:
            str = str + "0"
            break
        default:
            str = str.substringWithRange(Range(start: str.endIndex.advancedBy(-4), end: str.endIndex))
        }
        
        print(str)
        return str
    }
    
    
    static func checkByRegex(patten:String,text:String)->Bool{
        do{
            let regex = try NSRegularExpression(pattern: patten, options: .CaseInsensitive)
            let res = regex.matchesInString(text, options: NSMatchingOptions(rawValue: 0), range: NSMakeRange(0, text.characters.count))
            
            if res.count > 0{
                return true
            }
        }catch let error{
            print(error)
        }
        return false
    }
}
